home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Programming Contest / Test Code Folder / Problem 04 Test Code / Main.cp
Encoding:
Text File  |  1998-05-25  |  1.3 KB  |  60 lines  |  [TEXT/CWIE]

  1. #include "Solution.h"
  2.  
  3. #include "ProblemUtils.h"
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <Files.h>
  8. #include <Errors.h>
  9.  
  10. pascal OSErr CheckTextProcess( const FSSpec* infile, const FSSpec* outfile )
  11. {
  12.     OSErr err;
  13.     Handle data = NULL;
  14.     UInt32 action_count = 0;
  15.     ActionRecord action;
  16.     ActionRecord **actions = NULL;
  17.     char line[MAX_LINE_LEN];
  18.     char *p;
  19.     
  20.     actions = (ActionRecord **) NewHandle( 0 );
  21.     err = MemError();
  22.     if ( err == noErr ) {
  23.         err = ProblemFileRead( infile, &data );
  24.     }
  25.     if ( err == noErr ) {
  26.         while ( ProblemReadLineFromHandle( data, line, MAX_LINE_LEN ) ) {
  27.             if ( strcmp( line, "END" ) == 0 ) {
  28.                 break;
  29.             }
  30.             p = line;
  31.             if ( ProblemGetUInt32( &p, &action.action ) 
  32.                     && ProblemGetSInt32( &p, &action.amount ) 
  33.                     && ProblemGetUInt32( &p, &action.flags ) ) {
  34.                 ProblemGetString( &p, action.search );
  35.                 ProblemGetString( &p, action.replace );
  36.                 err = PtrAndHand( &action, (Handle) actions, sizeof(ActionRecord));
  37.                 action_count++;
  38.                 ProblemLogError( err, "CheckTextProcess: PtrAndHand" );
  39.             } else {
  40.                 ProblemLogError( -1, "CheckTextProcess: not numbers" );
  41.             }
  42.         }
  43.         HLock( (Handle) actions );
  44.         TextProcess( data, action_count, *actions );
  45.         err = ProblemFileWrite( outfile, data );
  46.         DisposeHandle( data );
  47.     }
  48.     return err;
  49. }
  50.  
  51. int main()
  52. {
  53.     printf( "Starting\n" );
  54.     
  55.     ProblemRunFileTests( CheckTextProcess );
  56.  
  57.     return 0;
  58. }
  59.  
  60.